home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / A / AxoCalculator Package / AxoCalculator Documentation / Programming in Fortran / Example Functions next >
Encoding:
Text File  |  1993-03-13  |  2.9 KB  |  93 lines  |  [TEXT/AxoC]

  1. LocalLanguage Fortran
  2. c    -------------------------------------------------------
  3. c    The following functions demonstrate various aspects of 
  4. c    AxoCalculator's Fortran programming language. 
  5. c
  6. c    •  To load all the demo functions, choose "Select All" 
  7. c        under the "Edit" menu, then press "enter". 
  8. c
  9. c    •  To run a function, type its name followed
  10. c        by any parameters, then press "enter".
  11. c
  12. c    •  After the functions are loaded, this file does 
  13. c        not need to remain open in order to use them.
  14. c
  15. c    •  Here are some examples of how to use the functions
  16. c        (remove the "c" at the start of each line before testing) .
  17. c
  18. c    BoxVolume (10,15,20)
  19. c    Factorial (10)
  20. c    RecursiveFact (10)
  21. c    SameBirthDateProb(25)
  22. c    --------------------------------------------------
  23.  
  24. c    ---------------- RectArea ------------------------
  25. c    This function calculates the area of a rectangle
  26. c    given its height and width.
  27. c    -------------------------------------------------
  28.     function RectArea (height, width)
  29.     RectArea = height * width
  30.     end
  31.  
  32. c    ---------------- BoxVolume ----------------------
  33. c    This function calculates the volume of a box 
  34. c    given its height, width and depth. It calls the
  35. c    function RectArea to get the area of the bottom of
  36. c    the box, then multiplies the result by the box depth. 
  37. c    -------------------------------------------------
  38.     function BoxVolume (height, width, depth)
  39.     BoxVolume = RectArea (height, width) * depth
  40.     end
  41.  
  42. c    ---------------- Factorial ---------------------
  43. c    This function calculates the factorial of a number.
  44. c    ----------------------------------------------
  45.     function Factorial (number)
  46.     integer i
  47.     real f
  48. c    ..............................................................................................................
  49.     f = 1
  50.     do i = 1, number 
  51.         f = f * i
  52.     enddo
  53.     Factorial = f
  54.     end
  55.  
  56. c    ---------------- RecursiveFact -------------------
  57. c  This function also calculates the factorial of a number,
  58. c  but it uses a recursive algorithm. This approach is
  59. c  inefficient, but demonstrates recursion.
  60. c    -----------------------------------------------}
  61.     function RecursiveFact (number)
  62.     if number > 1 then
  63.         RecursiveFact = number * RecursiveFact (number - 1)
  64.     else
  65.         RecursiveFact = 1
  66.     end
  67.  
  68.  
  69. c    ---------------- SameBirthDateProb ------------------
  70. c  This function calculates the probability that two or more
  71. c  people in a group have the same birth date, given the
  72. c  number of people in the group. It works by calculating
  73. c  1 - the probability that everyone in the group has a 
  74. c  different birth date.
  75. c    ----------------------------------------------------
  76.     function SameBirthDateProb (numberOfPeople)
  77.     if (numberOfPeople < 2) then 
  78.         DiffBirthDateProb = 1
  79.     else 
  80.         if (numberOfPeople > 365) then 
  81.             DiffBirthDateProb = 0
  82.         else
  83.             DiffBirthDateProb = 1
  84.             Do i = 2, numberOfPeople  
  85.                 DiffBirthDateProb = DiffBirthDateProb * (366-i) / 365
  86.             enddo
  87.         endif
  88.     endif
  89.     SameBirthDateProb = 1 - DiffBirthDateProb
  90.     end
  91.     
  92.  
  93.